package com.amkai.aes.webservice.binary.objecthandler.inventory;

import java.io.Serializable;

import org.hibernate.Query;

import com.amkai.aes.aescommon.service.binary.job.Job;
import com.amkai.aes.aescommon.service.binary.job.inventory.VendorOrderInformationPropertiesJob;
import com.amkai.aes.aescommon.service.binary.job.inventory.VendorOrderManufacterJob;
import com.amkai.aes.generatedbeans.common.Organization;
import com.amkai.aes.generatedbeans.inventory.VendorOrderInformation;
import com.amkai.aes.generatedbeans.inventory.items.UnitOfMeasure;
import com.amkai.aes.webservice.binary.JobObjectHandler;
import com.amkai.common.extensions.hibernate.config.SiteManager;
import com.amkai.common.extensions.hibernate.config.manager.SessionManager;

public class VendorOrderInformarionPropertiesHandler implements
		JobObjectHandler <VendorOrderInformationPropertiesJob,Serializable, UnitOfMeasure>{

	private static final String query = "select vo from VendorOrderInformation vo where vo.id = :voId";
	@Override
	public UnitOfMeasure process(
			VendorOrderInformationPropertiesJob job, Serializable object)
			throws Exception {
		SessionManager sm = SiteManager.Start();
		try {
		// TODO Auto-generated method stub
			sm.openSession();
			Query q;
			q = sm.execute(query);
			q.setLong("voId",job.voId);
			VendorOrderInformation v = (VendorOrderInformation)q.uniqueResult(); 
			if (v != null){
				v.getOrderingUnit().getId();
				v.getOrderingUnit().getName();
			}
			return v.getOrderingUnit();
		} catch (Exception e) {
			throw e;
		} finally {
			sm.closeSession();
		}		
	}

}
